//744.寻找比目标字母大的最小字母
class Solution {

    int islower_bound(vector<char>& nums,char target )
    {
        int left=-1;
        int right=nums.size();
        while(left+1<right)
        {
            int mid=left+(right-left)/2;
            if(nums[mid]<target) left=mid;
            else right=mid;
        }
        return right;
    }

public:
    char nextGreatestLetter(vector<char>& letters, char target) {
        int n=letters.size();
        int pos=islower_bound(letters,target+1);  //查找第一个大于等于target+1的位置

        return pos==n?letters[0]:letters[pos];
    }
};